#!/bin/sh
#Barry Kauler 2008.
#Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html). 2007 www.puppylinux.com
#a gui to provide choices for "events" -- things that occur at a systems level,
#usually hardware related.
#v411 checkbox to redraw/realign icons.
#v412 workaround, someone exited with invalid settings.
#w007 mouse inactivity computer power-down.
#w464 /etc/puppyversion is now history.
#v424 automatic unmounting (see pup_event_frontend_d).
#110505 support sudo for non-root user.
#120201 BK: internationalized.
#130212 /var/local/pup_event_icon_change_flag path changed from /tmp (see /sbin/clean_desk_icons)
#131123 zigbert: gui (gtkdialog) improvements.
#140101 SFR: added 'partitions labels' + 'placement' options
#140418 SFR: added 'ask at shutdown to save session' checkbox

[ "`whoami`" != "root" ] && exec sudo -A ${0} ${@} #110505

export TEXTDOMAIN=eventmanager
export OUTPUT_CHARSET=UTF-8

SHOWMODE=$1 #v405 optional to modify gui.

. /etc/rc.d/PUPSTATE
. /etc/DISTRO_SPECS
PUPPYVERSION="$DISTRO_VERSION"
KERNVER="`uname -r`"
. /etc/rc.d/MODULESCONFIG

[ -f /etc/eventmanager ] && . /etc/eventmanager
[ "$ICONDESK" != "true" -a "$ICONDESK" != "false" ] && ICONDESK="true"
[ ! $RAMSAVEINTERVAL ] && RAMSAVEINTERVAL=30
[ "$ASKTOSAVE" != "true" -a "$ASKTOSAVE" != "false" ] && ASKTOSAVE="false"
[ "$HOTPLUGNOISY" != "true" -a "$HOTPLUGNOISY" != "false" ] && HOTPLUGNOISY="false"
[ "$AUTOTARGET" != "true" -a "$AUTOTARGET" != "false" ] && AUTOTARGET="true"
[ "$ICONPARTITIONS" != "true" -a "$ICONPARTITIONS" != "false" ] && ICONPARTITIONS="true"
[ "$LABELPARTITIONS" != "true" -a "$LABELPARTITIONS" != "false" ] && LABELPARTITIONS="false"
[ "$HOTPLUGON" != "true" -a "$HOTPLUGON" != "false" ] && HOTPLUGON="true"
[ "$BACKENDON" != "true" -a "$BACKENDON" != "false" ] && BACKENDON="true"
[ "$FD0ICON" != "true" -a "$FD0ICON" != "false" ] && FD0ICON="true"
[ ! $POWERTIMEOUT ] && POWERTIMEOUT=0 #w007 0=never.
[ ! $AUTOUNMOUNT ] && AUTOUNMOUNT="false" #v424

[ "$ICON_PLACE_ORIENTATION" != "bottom" -a "$ICON_PLACE_ORIENTATION" != "top" -a "$ICON_PLACE_ORIENTATION" != "right" -a "$ICON_PLACE_ORIENTATION" != "left" ] && ICON_PLACE_ORIENTATION="bottom"
[ ! "$ICON_PLACE_EDGE_GAP" ] && ICON_PLACE_EDGE_GAP=64
[ ! "$ICON_PLACE_START_GAP" ] && ICON_PLACE_START_GAP=32
[ ! "$ICON_PLACE_SPACING" ] && ICON_PLACE_SPACING=64

#w007 as have a optional cutdown gui, make sure these are all preset...
NEWICONDESK="$ICONDESK"
NEWRAMSAVEINTERVAL=$RAMSAVEINTERVAL
NEWHOTPLUGNOISY="$HOTPLUGNOISY"
NEWAUTOTARGET="$AUTOTARGET"
NEWICONPARTITIONS="$ICONPARTITIONS"
NEWLABELPARTITIONS="$LABELPARTITIONS"
NEWHOTPLUGON="$HOTPLUGON"
NEWBACKENDON="$BACKENDON"
NEWFD0ICON="$FD0ICON"
NEWPOWERTIMEOUT=$POWERTIMEOUT
NEWAUTOUNMOUNT="$AUTOUNMOUNT"

case "$ICON_PLACE_ORIENTATION" in
  bottom)	ICON_PLACE_ORIENTATION="$(gettext "Bottom")" ;;
  top)		ICON_PLACE_ORIENTATION="$(gettext "Top")" ;;
  right)	ICON_PLACE_ORIENTATION="$(gettext "Right")" ;;
  left)		ICON_PLACE_ORIENTATION="$(gettext "Left")" ;;
esac
NEWICON_PLACE_ORIENTATION="$ICON_PLACE_ORIENTATION"
NEWICON_PLACE_EDGE_GAP="$ICON_PLACE_EDGE_GAP"
NEWICON_PLACE_START_GAP="$ICON_PLACE_START_GAP"
NEWICON_PLACE_SPACING="$ICON_PLACE_SPACING"

[ "$SHOWMODE" = "desktop" ] && PAGE_NR=2 || PAGE_NR=0

export Puppy_Event_Manager='
<window title="'$(gettext 'Puppy Event Manager')'" icon-name="gtk-execute">
<vbox space-expand="true" space-fill="true">
  <notebook tab-pos="2" page="'$PAGE_NR'" labels="'$(gettext 'Activate')'|'$(gettext 'Save Session')'|'$(gettext 'Desktop Icons')'|'$(gettext 'Power')'">
    <frame '$(gettext 'Activate Puppy Event Manager')'>
      '"`/usr/lib/gtkdialog/xml_info scale execute_yes.svg 60 "$(gettext "The 'pup_event' Puppy Event Manager runs in the background and handles hotplugging of drives, including the desktop drive icons. This also includes automatic module and firmware loading if new hardware is detected. However, turn it all off, and Puppy will revert to the same behaviour as versions prior to 4.x, in which there is no hotplug support. This reduces resource usage, so try unticking these on very old slow PCs. Pmount can still be run manually to mount and unmount partitions.")"`"'
      <vbox space-expand="false" space-fill="false">
        <text height-request="20"><label>""</label></text>
        <checkbox>
          <label>'$(gettext 'Activate Puppy Event Manager')'</label>
          <default>'${BACKENDON}'</default>
          <variable>NEWBACKENDON</variable>
          <action>if true enable:NEWHOTPLUGON</action>
          <action>if true enable:NEWAUTOUNMOUNT</action>
          <action>if false disable:NEWHOTPLUGON</action>
          <action>if false disable:NEWAUTOUNMOUNT</action>
        </checkbox>
        <checkbox>
          <label>'$(gettext 'Activate desktop hotplug support')'</label>
          <default>'${HOTPLUGON}'</default>
          <variable>NEWHOTPLUGON</variable>
        </checkbox>
        <checkbox tooltip-text="'$(gettext 'WARNING: auto unmounting is highly experimental')'">
          <label>'$(gettext 'Activate auto unmounting of partitions (-EXPERIMENTAL-)')'</label>
          <default>'${AUTOUNMOUNT}'</default>
          <variable>NEWAUTOUNMOUNT</variable>
        </checkbox>
        <text height-request="5"><label>""</label></text>
      </vbox>
    </frame>

    <frame '$(gettext 'Periodic save from RAM')'>
      <vbox space-expand="true" space-fill="true">
        '"`/usr/lib/gtkdialog/xml_info scale puppy_save.svg 60 "$(gettext "Puppy runs in a particular 'state' that we call the PUPMODE. This depends on the type of installation and the type of hardware. Currently, PUPMODE=")${PUPMODE}. $(gettext "If it is an odd number, for example 13, then Puppy is doing everything in RAM and saving the current session to a drive periodically -- this is done in the case of Flash memory to make it last longer. When Puppy runs in an odd PUPMODE, there will be a 'save' icon on the desktop, also a save occurs at shutdown. You can also specify a periodic save here")" " " "<b>$(gettext 'Note!')</b> $(gettext 'PUPMODE=77 (multisession DVD) excluded, only manual save with desktop icon and at shutdown.')" "<b>$(gettext 'Note!')</b> $(gettext 'PUPMODE=5 there are no saves, above value ignored.')"`"'
        <vbox space-expand="false" space-fill="false">
          <text height-request="20"><label>""</label></text>
          <hbox>
            <text space-expand="true" space-fill="true"><label>""</label></text>
            <text space-expand="false" space-fill="false"><label>"'$(gettext 'Save interval (0=never)')'  "</label></text>
            <entry max_length="4" width-request="40" space-expand="false" space-fill="false">
              <default>'${RAMSAVEINTERVAL}'</default>
              <variable>NEWRAMSAVEINTERVAL</variable>
              <action signal="key-release-event" condition="command_is_true([ \"`echo ${NEWRAMSAVEINTERVAL//[!0-9]} | tr -s '0'`\" = \"0\" ] && echo true )">show:VARASK</action>
              <action signal="key-release-event" condition="command_is_true([ \"`echo ${NEWRAMSAVEINTERVAL//[!0-9]} | tr -s '0'`\" != \"0\" ] && echo true )">hide:VARASK</action>
              <action signal="button-release-event" condition="command_is_true([ \"`echo ${NEWRAMSAVEINTERVAL//[!0-9]} | tr -s '0'`\" = \"0\" ] && echo true )">show:VARASK</action>
              <action signal="button-release-event" condition="command_is_true([ \"`echo ${NEWRAMSAVEINTERVAL//[!0-9]} | tr -s '0'`\" != \"0\" ] && echo true )">hide:VARASK</action>
            </entry>
            <text><label>"'$(gettext 'minutes')' "</label></text>
          </hbox>
          <text height-request="5"><label>""</label></text>
          
          <vbox>
            <hseparator></hseparator>
            <hbox homogeneous="true">
            <checkbox>
              <default>'${ASKTOSAVE}'</default>
              <variable>NEWASKTOSAVE</variable>
              <label>"'$(gettext 'Ask at shutdown whether to save session or not.')'"</label>
            </checkbox>
            </hbox>
            <text><label>"'$(gettext '(if unticked, session will be saved automatically)')'"</label></text>
            <variable>VARASK</variable>
          </vbox>
        
        </vbox>
      </vbox>
    </frame>

    <notebook tab-pos="2" labels="'$(gettext 'Show Icons')'|'$(gettext 'Icon Handler')'|'$(gettext 'Floppy drive')'|'$(gettext 'Power')'">
      <frame '$(gettext 'Drive icons on desktop')'>
        <vbox space-expand="true" space-fill="true">
          '"`/usr/lib/gtkdialog/xml_info scale desktop_icons.svg 60 "$(gettext "When this box is ticked, there will be an icon for each drive. If you plugin a USB pen drive for example, an icon will appear. Unplug and it will disappear. If you don't want these drive icons on the desktop, untick this box (but there will still remain just one icon that will launch Pmount when clicked on). The individual drive icons are purely a convenience and Puppy works fine without them.")"`"'
          <vbox space-expand="false" space-fill="false">
            <text height-request="20"><label>""</label></text>
            
            <hbox>
              <vbox homogeneous="true">
                <checkbox>
                  <label>'$(gettext 'Show desktop icons for each DRIVE')'</label>
                  <default>'${ICONDESK}'</default>
                  <variable>NEWICONDESK</variable>
                  <action>if true enable:NEWICONPARTITIONS</action>
                  <action>if true enable:NEWICON_PLACE_ORIENTATION</action>
                  <action>if true enable:NEWICON_PLACE_EDGE_GAP</action>
                  <action>if true enable:NEWICON_PLACE_START_GAP</action>
                  <action>if true enable:NEWICON_PLACE_SPACING</action>
                  <action>if false disable:NEWICONPARTITIONS</action>
                  <action>if false disable:NEWICON_PLACE_ORIENTATION</action>
                  <action>if false disable:NEWICON_PLACE_EDGE_GAP</action>
                  <action>if false disable:NEWICON_PLACE_START_GAP</action>
                  <action>if false disable:NEWICON_PLACE_SPACING</action>
                  <action condition="sensitive_is_true(NEWICONPARTITIONS)">enable:NEWLABELPARTITIONS</action>
			      <action condition="sensitive_is_false(NEWICONPARTITIONS)">disable:NEWLABELPARTITIONS</action>
                  <action condition="active_is_false(NEWICONPARTITIONS)">disable:NEWLABELPARTITIONS</action>
                </checkbox>
                <checkbox>
                  <label>'$(gettext 'Show desktop icons for each PARTITION')'</label>
                  <default>'${ICONPARTITIONS}'</default>
                  <variable>NEWICONPARTITIONS</variable>
                  <action>if true enable:NEWLABELPARTITIONS</action>
                  <action>if false disable:NEWLABELPARTITIONS</action>
                </checkbox>
                <checkbox>
                  <label>'$(gettext 'Show labels for each PARTITION')'</label>
                  <default>'${LABELPARTITIONS}'</default>
                  <variable>NEWLABELPARTITIONS</variable>
                </checkbox>
                <checkbox>
                  <label>'$(gettext 'Refresh / Realign existing icons')'</label>
                  <default>false</default>
                  <variable>NEWICONWIPE</variable>
                </checkbox>
              </vbox>
            
              <vseparator></vseparator>
              <text space-fill="true" space-expand="true"><label>""</label></text>
            
              <vbox>
                <hbox>
                  <text xalign="0"><label>'$(gettext 'Placement: ')'</label></text>
                  <text space-fill="true" space-expand="true"><label>""</label></text>
                  <comboboxtext>
                    <default>'${ICON_PLACE_ORIENTATION}'</default>
                    <variable>NEWICON_PLACE_ORIENTATION</variable>
                    <item>'$(gettext 'Top')'</item>
                    <item>'$(gettext 'Bottom')'</item>
                    <item>'$(gettext 'Left')'</item>
                    <item>'$(gettext 'Right')'</item>
                  </comboboxtext>
                </hbox>
                <hbox>
                  <text xalign="0"><label>'$(gettext 'Start gap: ')'</label></text>
                  <text space-fill="true" space-expand="true"><label>""</label></text>
                  <spinbutton range-min="32" range-max="1024" range-step="1" range-value="'${ICON_PLACE_START_GAP}'">
                    <variable>NEWICON_PLACE_START_GAP</variable>
                  </spinbutton>
                </hbox>
                <hbox>
                  <text xalign="0"><label>'$(gettext 'Edge gap: ')'</label></text>
                  <text space-fill="true" space-expand="true"><label>""</label></text>
                  <spinbutton range-min="32" range-max="1024" range-step="1" range-value="'${ICON_PLACE_EDGE_GAP}'">
                    <variable>NEWICON_PLACE_EDGE_GAP</variable>
                  </spinbutton>
                </hbox>
                <hbox>
                  <text xalign="0"><label>'$(gettext 'Spacing: ')'</label></text>
                  <text space-fill="true" space-expand="true"><label>""</label></text>
                  <spinbutton range-min="48" range-max="256" range-step="1" range-value="'${ICON_PLACE_SPACING}'">
                    <variable>NEWICON_PLACE_SPACING</variable>
                  </spinbutton>
                </hbox>
              </vbox>     
            </hbox>
            <text height-request="5"><label>""</label></text>
          </vbox>
        </vbox>
      </frame>

      <frame '$(gettext "Drive 'handler'")'>
        <vbox space-expand="true" space-fill="true">
         '"`/usr/lib/gtkdialog/xml_info scale cd_audio.svg 60 "$(gettext "The 'handler' decides what to do when you click on a desktop drive icon. Normally, this just starts Pmount if you click on a drive icon. For partitions, it mounts and shows content in a file browser. This behavior can be extended...")"`"'
          <vbox space-expand="false" space-fill="false">
            <checkbox>
              <label>'$(gettext 'Auto-play video-DVD and audio-CD')'</label>
              <default>'${AUTOTARGET}'</default>
              <variable>NEWAUTOTARGET</variable>
            </checkbox>
            <text height-request="5"><label>""</label></text>
          </vbox>
        </vbox>
        <vbox space-expand="true" space-fill="true">
          '"`/usr/lib/gtkdialog/xml_info scale cd_mount.svg 60 "$(gettext "Normally you have to click on a drive icon to run the 'handler', but this checkbox makes the 'handler' run as soon as a media is plugged in. For example, plug in a DVD and it will immediately either get mounted, or if the above checkbox is ticked the media player will run.")"`"'
          <vbox space-expand="false" space-fill="false">
            <checkbox>
              <label>'$(gettext "Auto-launch 'handler' when media plugged in")'</label>
              <default>'${HOTPLUGNOISY}'</default>
              <variable>NEWHOTPLUGNOISY</variable>
            </checkbox>
            <text height-request="5"><label>""</label></text>
          </vbox>
        </vbox>
      </frame>

      <frame Floppy drive>
        <vbox space-expand="true" space-fill="true">
          '"`/usr/lib/gtkdialog/xml_info scale floppy.svg 60 "$(gettext 'Linux does not support hotplug detection of when a legacy floppy diskette is inserted or removed. Periodic probing requires starting the drive motor, which is very slow -- and do you want the motor to startup every 4 seconds? Therefore, if your PC has a floppy drive, tick this box to have a permanent icon on desktop (regardless whether a diskette is actually inserted, or even a floppy drive!).')"`"'
          <vbox space-expand="false" space-fill="false">
            <text height-request="20"><label>""</label></text>
            <checkbox>
              <label>'$(gettext 'Add floppy drive icon on desktop')'</label>
              <default>'${FD0ICON}'</default>
              <variable>NEWFD0ICON</variable>
            </checkbox>
            <text height-request="5"><label>""</label></text>
          </vbox>
        </vbox>
      </frame>
    </notebook>

    <frame '$(gettext 'Power')'>
      <vbox space-expand="true" space-fill="true">
        '"`/usr/lib/gtkdialog/xml_info scale shutdown_interval.svg 60 "$(gettext 'Puppy is able to power-off your computer after a period of mouse inactivity. This will occur if the mouse cursor has not been moved for the designated interval.')"`"'
        <vbox space-expand="false" space-fill="false">
          <text height-request="20"><label>""</label></text>
          <hbox>
            <text space-expand="true" space-fill="true"><label>""</label></text>
            <text space-expand="false" space-fill="false"><label>"'$(gettext 'Inactivity interval (0=never)')'  "</label></text>
            <entry max_length="4" width-request="40" space-expand="false" space-fill="false">
              <default>'${POWERTIMEOUT}'</default>
              <variable>NEWPOWERTIMEOUT</variable>
            </entry>
            <text><label>"'$(gettext 'minutes')' "</label></text>
          </hbox>
          <text height-request="5"><label>""</label></text>
        </vbox>
      </vbox>
    </frame>
  </notebook>

  <hbox space-expand="false" space-fill="false">
    <text use-markup="true" space-expand="false" space-fill="false"><label>" <b>'$(gettext 'Restart X for changes to take effect')'</b>"</label></text>
    <text space-expand="true" space-fill="true"><label>""</label></text>
    <button space-expand="false" space-fill="false">
      <label>'$(gettext "Cancel")'</label>
      '"`/usr/lib/gtkdialog/xml_button-icon cancel`"'
      <action>exit:Cancel</action>
    </button>
    <button space-expand="false" space-fill="false">
      <label>'$(gettext "Ok")'</label>
      '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
      <action>exit:OK</action>
    </button>
  </hbox>
</vbox>
<action signal="show" condition="command_is_true([[ '${BACKENDON}' != true ]] && echo true)">disable:NEWHOTPLUGON</action>
<action signal="show" condition="command_is_true([[ '${BACKENDON}' != true ]] && echo true)">disable:NEWAUTOUNMOUNT</action>
<action signal="show" condition="command_is_true([[ '${ICONDESK}' != true ]] && echo true)">disable:NEWICONPARTITIONS</action>
<action signal="show" condition="command_is_true([[ '${ICONDESK}' != true ]] && echo true)">disable:NEWLABELPARTITIONS</action>
<action signal="show" condition="command_is_true([[ '${ICONPARTITIONS}' != true ]] && echo true)">disable:NEWLABELPARTITIONS</action>
<action signal="show" condition="command_is_true([[ '${ICONDESK}' != true ]] && echo true)">disable:NEWICON_PLACE_ORIENTATION</action>
<action signal="show" condition="command_is_true([[ '${ICONDESK}' != true ]] && echo true)">disable:NEWICON_PLACE_EDGE_GAP</action>
<action signal="show" condition="command_is_true([[ '${ICONDESK}' != true ]] && echo true)">disable:NEWICON_PLACE_START_GAP</action>
<action signal="show" condition="command_is_true([[ '${ICONDESK}' != true ]] && echo true)">disable:NEWICON_PLACE_SPACING</action>
<action signal="show" condition="command_is_true([ '${RAMSAVEINTERVAL}' -ne 0 ] && echo true )">hide:VARASK</action>
</window>'

. /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
RETSTRING="`gtkdialog -p Puppy_Event_Manager`"
[ $? -ne 0 ] && exit

eval "$RETSTRING"

#echo "$RETSTRING" #TEST

[ "$EXIT" = "abort" ] && exit
[ "$EXIT" = "Cancel" ] && exit
[ "$EXIT" = "" ] && exit

#v405 it is running with 'desktop' param, now rerun with all tabs...
[ "$EXIT" = "fullem" ] && exec eventmanager

#make sure that RAMSAVEINTERVAL is an integer only...
[ "$NEWRAMSAVEINTERVAL" = "" ] && NEWRAMSAVEINTERVAL=30 #412
NEWRAMSAVEINTERVAL=`echo -n "$NEWRAMSAVEINTERVAL" | sed -e 's/[^0-9]//g'`
#do not allow too-frequent saves...
[ $NEWRAMSAVEINTERVAL -gt 0 -a $NEWRAMSAVEINTERVAL -lt 5 ] && NEWRAMSAVEINTERVAL=5

#make sure 'ask to save' dialog won't appear at shutdown, if save interval > 0
[ $NEWRAMSAVEINTERVAL -ne 0 ] && NEWASKTOSAVE=false

#w007 make sure that POWERTIMEOUT is integer only...
[ "$NEWPOWERTIMEOUT" = "" ] && NEWPOWERTIMEOUT=0
NEWPOWERTIMEOUT=`echo -n "$NEWPOWERTIMEOUT" | sed -e 's/[^0-9]//g'`
#do not allow too-frequent power-down...
[ $NEWPOWERTIMEOUT -gt 0 -a $NEWPOWERTIMEOUT -lt 5 ] && NEWPOWERTIMEOUT=5

#v403 if major-switch has turned off hotplug support, only show one icon...
[ "$NEWBACKENDON" = "" ] && NEWBACKENDON="true" #v412
[ "$NEWHOTPLUGON" = "" ] && NEWHOTPLUGON="true" #v412
[ "$NEWBACKENDON" = "false" ] && NEWHOTPLUGON="false"
if [ "$NEWHOTPLUGON" = "false" ];then
 NEWICONDESK="false"
 NEWICONPARTITIONS="false"
 NEWLABELPARTITIONS="false"
 NEWHOTPLUGNOISY="false"
 NEWAUTOTARGET="false"
 NEWAUTOUNMOUNT="false" #v424
fi

#v403 /sbin/clean_desk_icons can read this, then wipe all current icons... 120213 path changed from /tmp (see /sbin/clean_desk_icons)...
[ "$LABELPARTITIONS" != "$NEWLABELPARTITIONS" ] && echo "LABELPARTITIONS" > /var/local/pup_event_icon_change_flag
[ "$ICONPARTITIONS" != "$NEWICONPARTITIONS" ] && echo "ICONPARTITIONS" > /var/local/pup_event_icon_change_flag
[ "$ICONDESK" != "$NEWICONDESK" ] && echo "ICONDESK" > /var/local/pup_event_icon_change_flag
[ "$NEWICONWIPE" = "true" ] && echo "ICONWIPE" > /var/local/pup_event_icon_change_flag #v411

case "$NEWICON_PLACE_ORIENTATION" in
  "$(gettext "Bottom")")	NEWICON_PLACE_ORIENTATION="bottom" ;;
  "$(gettext "Top")")		NEWICON_PLACE_ORIENTATION="top" ;;
  "$(gettext "Left")")		NEWICON_PLACE_ORIENTATION="left" ;;
  "$(gettext "Right")")		NEWICON_PLACE_ORIENTATION="right" ;;
  *)						NEWICON_PLACE_ORIENTATION="bottom" ;;	#precaution
esac

CONFIG="`cat /etc/eventmanager`"

rsPATTERN="s/^RAMSAVEINTERVAL=.*/RAMSAVEINTERVAL=${NEWRAMSAVEINTERVAL}/"
CONFIG="`echo "$CONFIG" | sed -e "$rsPATTERN"`"

asPATTERN="s/^ASKTOSAVE=.*/ASKTOSAVE=${NEWASKTOSAVE}/"
CONFIG="`echo "$CONFIG" | sed -e "$asPATTERN"`"

#w007...
ptPATTERN="s/^POWERTIMEOUT=.*/POWERTIMEOUT=${NEWPOWERTIMEOUT}/"
CONFIG="`echo "$CONFIG" | sed -e "$ptPATTERN"`"

idPATTERN="s/^ICONDESK=.*/ICONDESK=${NEWICONDESK}/"
CONFIG="`echo "$CONFIG" | sed -e "$idPATTERN"`"

ipPATTERN="s/^ICONPARTITIONS=.*/ICONPARTITIONS=${NEWICONPARTITIONS}/"
CONFIG="`echo "$CONFIG" | sed -e "$ipPATTERN"`"

lpPATTERN="s/^LABELPARTITIONS=.*/LABELPARTITIONS=${NEWLABELPARTITIONS}/"
CONFIG="`echo "$CONFIG" | sed -e "$lpPATTERN"`"

hnPATTERN="s/^HOTPLUGNOISY=.*/HOTPLUGNOISY=${NEWHOTPLUGNOISY}/"
CONFIG="`echo "$CONFIG" | sed -e "$hnPATTERN"`"

atPATTERN="s/^AUTOTARGET=.*/AUTOTARGET=${NEWAUTOTARGET}/"
CONFIG="`echo "$CONFIG" | sed -e "$atPATTERN"`"

hoPATTERN="s/^HOTPLUGON=.*/HOTPLUGON=${NEWHOTPLUGON}/"
CONFIG="`echo "$CONFIG" | sed -e "$hoPATTERN"`"

boPATTERN="s/^BACKENDON=.*/BACKENDON=${NEWBACKENDON}/"
CONFIG="`echo "$CONFIG" | sed -e "$boPATTERN"`"

fiPATTERN="s/^FD0ICON=.*/FD0ICON=${NEWFD0ICON}/"
CONFIG="`echo "$CONFIG" | sed -e "$fiPATTERN"`"

auPATTERN="s/^AUTOUNMOUNT=.*/AUTOUNMOUNT=${NEWAUTOUNMOUNT}/" #v424
CONFIG="`echo "$CONFIG" | sed -e "$auPATTERN"`"

poPATTERN="s/^ICON_PLACE_ORIENTATION=.*/ICON_PLACE_ORIENTATION=${NEWICON_PLACE_ORIENTATION}/"
CONFIG="`echo "$CONFIG" | sed -e "$poPATTERN"`"

egPATTERN="s/^ICON_PLACE_EDGE_GAP=.*/ICON_PLACE_EDGE_GAP=${NEWICON_PLACE_EDGE_GAP}/"
CONFIG="`echo "$CONFIG" | sed -e "$egPATTERN"`"

sgPATTERN="s/^ICON_PLACE_START_GAP=.*/ICON_PLACE_START_GAP=${NEWICON_PLACE_START_GAP}/"
CONFIG="`echo "$CONFIG" | sed -e "$sgPATTERN"`"

psPATTERN="s/^ICON_PLACE_SPACING=.*/ICON_PLACE_SPACING=${NEWICON_PLACE_SPACING}/"
CONFIG="`echo "$CONFIG" | sed -e "$psPATTERN"`"

echo "$CONFIG" > /etc/eventmanager

###END###
